package com.edu.koTA07.adapter;

import java.util.ArrayList;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import com.edu.koTA07.bean.BarangBean;
import com.edu.koTA07.takingOrder.R;

public class BarangListAdapter extends BaseAdapter {

	ArrayList<BarangBean> barangs;
	Context context;
	// private ImageLoader imageLoader;
	public BarangListAdapter(Context context,
			ArrayList<BarangBean> barangs) {
		// TODO Auto-generated constructor stub
		super();
		inflater = (LayoutInflater) context
		.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		this.barangs = barangs;
		this.context = context;
		//forceReload();
	}
	private static LayoutInflater inflater = null;

	public int getCount() {
		return barangs.size();
	}

	public BarangBean getItem(int position) {
		return (null == barangs) ? null : barangs.get(position);
	}

	public long getItemId(int position) {
		return position;
	}
	
	class ViewHolder {
		TextView textLine;
	     ImageView iconLine;
	     Button buttonLine;
	}
	
	public View getView(int position, View convertView, ViewGroup parent) {

		ViewHolder holder;
		View vi = convertView;
		
		if (convertView == null) {
			vi = inflater.inflate(R.layout.content_barang, null);
			holder = new ViewHolder();
			holder.textLine = (TextView) vi.findViewById(R.id.textLine);
			vi.setTag(holder);
		}
		else 
			holder = (ViewHolder) vi.getTag();
		
		String barang = barangs.get(position).getNamaBarang();
		holder.textLine.setText(barang);
		return vi;
	}
	public void forceReload() {
		notifyDataSetChanged();
	}	
}
